package kr.hkit.powerjava.chapter22.work;

import java.util.ArrayList;

public class DepartmentDAO implements DaoInterface<Department> {
	private ArrayList<Department> arList;
	
	public DepartmentDAO(ArrayList<Department> arList) {
		this.arList = arList;
	}

	@Override
	public void addItem(Department item) {
		arList.add(item);
	}

	@Override
	public Department searchItem(Department item) {
		if (arList.contains(item)){
			return arList.get(arList.indexOf(item));
		}else{
			return null;
		}
	}

	@Override
	public void updateItem(Department item) {
		arList.set(arList.indexOf(item), item);
	}

	@Override
	public void delItem(Department item) {
		if (arList.contains(item)){
			arList.remove(arList.indexOf(item));
		}else{
			System.out.println("해당 학과 정보 없음");
		}
	}

	@Override
	public void prnList() {
		prnHeader();
		for(Department dept: arList){
			System.out.println(dept);
		}
	}

	@Override
	public void prnHeader() {
		String header = String.format("%3s\t%5s\t%3s","학과번호", "학과명", "위치");
		System.out.println(header);
	}

}
